package com.wowangz.cms.systemmanage.home.api;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wowangz.cms.common.utils.SysConstant;
import com.wowangz.cms.dailyoperation.store.service.StoreService;
import com.wowangz.cms.syscore.IssTransactionContainer;
import com.wowangz.cms.syscore.api.BaseController;
import com.wowangz.cms.systemmanage.userduty.service.UserDutyService;
import com.wowangz.cms.user.service.UserService;

@Controller
@Scope("prototype")
public class HomePageController extends BaseController {

	@RequestMapping(value = "/systemmanage/index/toHomePage.web")
	public String toHomePage(HttpServletRequest request, HttpServletResponse response, Model model) {

		try {
			// 用户复合的数量
			UserService userService = (UserService) IssTransactionContainer.getInstance(UserService.class, false);
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("statusid", SysConstant.RecordStatus.VALID);
			map.put("checkstatus", SysConstant.CheckStatus.SAVE);
			map.put("loginuserid", userContext.getLoginUser().getId());
			map.put("sort", "id");
			map.put("order", "desc");
			// 用户复合的数量
			long userCheckCount = userService.queryCheckUserCount(map);
			model.addAttribute("userCheckCount", userCheckCount);

			// 商户复合信息的数量
			map = new HashMap<String, Object>();
			map.put("apply", true);
			map.put("sort", "id");
			map.put("order", "desc");
			map.put("state", SysConstant.CommonApproveStatus.SUBMITTED);
			map.put("modifyuserid", getUserContext().getLoginUser().getId());
			map.put("statusid", SysConstant.RecordStatus.VALID);
			StoreService storeService = (StoreService) IssTransactionContainer.getInstance(StoreService.class, false);
			long storeCount = storeService.findResultCount(map);
			model.addAttribute("storeCount", storeCount);

			// 用户职责复合的数量
			map = new HashMap<String, Object>();
			map.put("sort", "id");
			map.put("order", "desc");
			map.put("statusid", SysConstant.RecordStatus.VALID);
			map.put("checkstatus", SysConstant.CheckStatus.CHECKED);
			map.put("poststatus", SysConstant.CheckStatus.SAVE);
			map.put("modifyuserid", getUserContext().getLoginUser().getId());// 交叉复核必须条件
			UserDutyService userDutyService = (UserDutyService) IssTransactionContainer.getInstance(UserDutyService.class, false);
			long userDutyCount = userDutyService.findResultCount(map);
			model.addAttribute("userDutyCount", userDutyCount);
			
			// 开通的商户数量
			map = new HashMap<String, Object>();
			map.put("sort", "id");
			map.put("order", "desc");
			map.put("state", SysConstant.CommonApproveStatus.OK);
			map.put("statusid", SysConstant.RecordStatus.VALID);
			long openStoreCount = storeService.findResultCount(map);
			model.addAttribute("openStoreCount", openStoreCount);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "/WEB-INF/jsp/systemmanage/home/homePage";
	}

	/**
	 * 
	 * @Title: toWelcomePage 
	 * @Description: 进入欢迎页
	 * @return String
	 * @author Green.Long
	 * @date 2016年8月16日 上午11:28:37
	 */
	@RequestMapping(value = "/systemmanage/index/toWelcomePage.web")
	public String toWelcomePage(HttpServletRequest request, HttpServletResponse response, Model model) {
		
		return "/WEB-INF/jsp/systemmanage/home/welcomePage";
	}
}
